from rest_framework import serializers

from apps.goods.models import SKU
from apps.orders.models import OrderInfo, OrderGoods


######sku商品序列化器##########
class SKUSerializer(serializers.ModelSerializer):

    class Meta:
        model = SKU
        fields=("name","default_image")

#再定义一个订单商品序列化器
class OrderGoodsSerializer(serializers.ModelSerializer):
    # 嵌套返回 订单商品嵌套sku商品返回
    sku = SKUSerializer()

    class Meta:
        model = OrderGoods
        fields=("count","price","sku")


class OrderInfoSerializer(serializers.ModelSerializer):
    # 关联嵌套返回 订到基本信息表嵌套订单商品返回,
    # 父表嵌套子表返回
    skus = OrderGoodsSerializer(many=True)

    class Meta:
        model = OrderInfo
        fields="__all__"


